package com.hqyj.project.controller;


import com.hqyj.project.dto.LeaveDto;

import com.hqyj.project.mapper.LeaveMapper;
import com.hqyj.project.service.LeaveService;
import com.hqyj.project.utils.CommonResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/leave")
public class LeaveController {
    @Autowired
    private LeaveService leaveService;

    @ResponseBody
    @GetMapping("/info")
    public CommonResult selectInfo(LeaveDto leaveDto){
        return leaveService.selectInfo(leaveDto);
    }

    //申请请假，并且附上信息
    @PostMapping("/apply")
    @ResponseBody
    public CommonResult applyToLeave(@RequestBody LeaveDto leaveDto){
        return leaveService.ApplyToLeave(leaveDto);
    }

    //审批准许通过
    @PutMapping("/permit/{userName}")
    @ResponseBody
    @RequiresRoles(value = {"admin","manager"},logical = Logical.OR)
    public CommonResult permit(@PathVariable String userName){
        return leaveService.permit(userName);
    }

    //个人查看申请状态方法
    @GetMapping("/leavePersonal/{userName}")
    @ResponseBody
    public CommonResult leavePersonal(@PathVariable String userName){
        return leaveService.selectPersonal(userName);
    }

    //审批驳回
    @PutMapping("/notPermit/{userName}")
    @ResponseBody
    public CommonResult notPermit(@PathVariable String userName){
        return leaveService.notPermit(userName);
    }

    @PutMapping("/updatestart/{userName}")
    @ResponseBody
    public CommonResult updateStart(@PathVariable String userName){
        return leaveService.updateStart(userName);
    }


//    //请假状态条件查询
//    @GetMapping("/leavestatus")
//    @ResponseBody
//    public CommonResult selectByLeaveStatus( leaveStatus){
//        return leaveService.selectByLeaveStatus(leaveStatus);
//    }
}
